<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:ui="http://java.sun.com/jsf/facelets"
      xmlns:p="http://primefaces.org/ui"
      xmlns:h="http://java.sun.com/jsf/html"
      xmlns:f="http://java.sun.com/jsf/core"
      xmlns:bi="http://java.sun.com/jsf/composite/bill">

    <h:body>
        <ui:composition template="/resources/template/template.xhtml">

            <ui:define name="content">
                <h:form>
                    <p:panel header="Reprint" >
                        <f:facet name="header" >
                            <h:outputLabel value="Reprint" ></h:outputLabel>
                            <hr/>

                            <p:commandButton ajax="false" value="Cancel" action="bill_cancel" disabled="#{billSearch.bill.cancelled}" onclick="onSubmitButton();" >                           
                            </p:commandButton>
                            <p:commandButton ajax="false" value="Refund" action="bill_refund" disabled="#{billSearch.bill.cancelled}" onclick="onSubmitButton();" >                          
                            </p:commandButton>
                        </f:facet>

                        <p:panel>
                            <p:panelGrid columns="2" style="width: 100%;">
                                <p:panel header="Patient Detail">
                                    <p:panelGrid columns="2">
                                        <h:outputLabel value="Collecting Centre ​Name:" ></h:outputLabel>
                                        <h:panelGroup>
                                            <p:autoComplete  forceSelection="true" value="#{billSearch.bill.collectingCentre}" 
                                                             completeMethod="#{collectingCentreController.completeCollecting}" var="ix" 
                                                             itemLabel="#{ix.name}" itemValue="#{ix}" size="30"  style="width: 400px;">
                                                <p:column>
                                                    #{ix.name}
                                                </p:column>
                                                <p:column>
                                                    #{ix.institutionCode}
                                                </p:column>
                                            </p:autoComplete>
                                            <p:commandButton ajax="false" value="Change" action="#{billSearch.update}"
                                                             disabled="#{!webUserController.hasPrivilege('ChangeCollectingCentre')}" onclick="onSubmitButton();" />
                                        </h:panelGroup>
                                        <h:outputLabel value="Age" />
                                        <h:outputLabel value="#{billSearch.bill.patient.age}"  />
                                        <h:outputLabel value="Sex" >
                                        </h:outputLabel>
                                        <h:outputLabel value="#{billSearch.bill.patient.person.sex}" >
                                        </h:outputLabel>
                                        <h:outputLabel value="Phone" >
                                        </h:outputLabel>
                                        <h:outputLabel value="#{billSearch.bill.patient.person.phone}" >
                                        </h:outputLabel>
                                    </p:panelGrid>
                                </p:panel>
                                <p:panel header="Bill Detail">
                                    <p:panelGrid columns="2">
                                        <h:outputLabel value="Bill No :" ></h:outputLabel>
                                        <h:outputLabel value="#{billSearch.bill.insId}" ></h:outputLabel>
                                        <h:outputLabel value="Payment Type : " ></h:outputLabel>
                                        <h:outputLabel value="#{billSearch.bill.paymentMethod}" ></h:outputLabel>

                                        <h:outputLabel value="Total :" ></h:outputLabel>
                                        <h:outputLabel value="#{billSearch.bill.total}" ></h:outputLabel>
                                        <h:outputLabel value="Discount :" ></h:outputLabel>
                                        <h:outputLabel value="#{billSearch.bill.discount}" ></h:outputLabel>
                                        <h:outputLabel value="Net Total :" ></h:outputLabel>
                                        <h:outputLabel value="#{billSearch.bill.netTotal}" ></h:outputLabel>
                                    </p:panelGrid>
                                </p:panel>
                            </p:panelGrid>
                            <p:panel header="Bill Item Detail">
                                <p:dataTable rowIndexVar="rowIndex" editable="true" value="#{billSearch.billFees2}" var="bip" >
                                    <p:ajax event="rowEdit" listener="#{billSearch.onEdit}" />  
                                    <p:ajax event="rowEditCancel" listener="#{billSearch.onEdit}" />  
                                    <p:column>
                                        <f:facet name="header">No</f:facet>
                                        <h:outputLabel value="#{rowIndex+1}"/>
                                    </p:column>
                                    <p:column>
                                        <f:facet name="header">Item</f:facet>
                                        <h:outputLabel value="#{bip.billItem.item.name}"/>
                                    </p:column>
                                    <p:column>
                                        <f:facet name="header">Fee</f:facet>
                                        <h:outputLabel value="#{bip.feeValue}"/>
                                    </p:column>  
                                    <p:column>
                                        <f:facet name="header">Fee Name</f:facet>
                                        <h:outputLabel value="#{bip.fee.name}"/>
                                    </p:column> 
                                    <p:column>
                                        <f:facet name="header">Speciality</f:facet>
                                        <h:outputLabel value="#{bip.fee.speciality.name}"/>
                                    </p:column> 
                                    <p:column headerText="Payee">
                                        <p:cellEditor>  
                                            <f:facet name="output"> 
                                                <h:outputLabel value="#{bip.staff.person.name}"  ></h:outputLabel>
                                            </f:facet>  
                                            <f:facet name="input">  
                                                <p:selectOneMenu value="#{bip.staff}" rendered="#{bip.fee.speciality!=null}" disabled="#{bip.paidValue!=0 or !webUserController.hasPrivilege('ChangeProfessionalFee')}" >
                                                    <f:selectItem itemLabel="Select Staff" />
                                                    <f:selectItems  value="#{staffController.getSpecialityStaff(bip.fee.speciality)}" var="bifs" itemLabel="#{bifs.person.name}" itemValue="#{bifs}" />
                                                </p:selectOneMenu>
                                            </f:facet>  
                                        </p:cellEditor>  

                                    </p:column>
                                    <p:column style="width:6%">  
                                        <p:rowEditor > 
                                        </p:rowEditor>
                                    </p:column>  
                                </p:dataTable>
                            </p:panel>
                        </p:panel>
                    </p:panel>




                    <h:panelGroup  >
                        <div id="centrewrapper">
                            <div id="centrecell">
                                <div class="centrecontent">
                                    <p:commandButton value="Print" ajax="false" action="#"   >
                                        <p:printer target="gpBillPreview" ></p:printer>
                                    </p:commandButton>


                                    <h:outputStylesheet library="css" name="printing.css"></h:outputStylesheet>

                                    <div style="border: 1px solid;" >
                                        <h:panelGroup id="gpBillPreview" >

                                            <div  class="fiveinchbill">


                                                <div  class="receiptno">
                                                    <h:outputLabel value="#{billSearch.bill.cancelledBill.insId} **Cancelled"  
                                                                   rendered="#{billSearch.bill.cancelledBill.insId ne null}"/> 

                                                    <h:outputLabel value="#{billSearch.bill.refundedBill.insId} **Refunded" 
                                                                   rendered="#{billSearch.bill.refundedBill.insId ne null}"/> 

                                                    <h:outputLabel value="#{billSearch.bill.insId} **Duplicate" 
                                                                   rendered="#{billSearch.bill.refundedBill.insId eq null and
                                                                               billSearch.bill.cancelledBill.insId eq null }"/> 
                                                </div>

                                                <div  class="billdate">
                                                    <h:outputLabel value="#{billSearch.bill.cancelledBill.billDate}"
                                                                   rendered="#{billSearch.bill.cancelledBill.insId ne null}"  >
                                                        <f:convertDateTime pattern="dd/MM/yy"/>
                                                    </h:outputLabel>
                                                    <h:outputLabel value="#{billSearch.bill.refundedBill.billDate}"
                                                                   rendered="#{billSearch.bill.refundedBill.insId ne null}">
                                                        <f:convertDateTime pattern="dd/MM/yy"/>
                                                    </h:outputLabel>
                                                    <h:outputLabel value="#{billSearch.bill.billDate}"
                                                                   rendered="#{billSearch.bill.refundedBill.insId eq null and 
                                                                               billSearch.bill.cancelledBill.insId eq null }">
                                                        <f:convertDateTime pattern="dd/MM/yy"/>
                                                    </h:outputLabel>
                                                </div>

                                                <div class="payment">
                                                    <h:outputLabel value="#{billSearch.bill.cancelledBill.paymentMethod}" 
                                                                   rendered="#{billSearch.bill.cancelledBill.insId ne null}" />
                                                    <h:outputLabel value="#{billSearch.bill.refundedBill.paymentMethod}" 
                                                                   rendered="#{billSearch.bill.refundedBill.insId ne null}"/>
                                                    <h:outputLabel value="#{billSearch.bill.paymentMethod}" 
                                                                   rendered="#{billSearch.bill.refundedBill.insId eq null and 
                                                                               billSearch.bill.cancelledBill.insId eq null }"/>
                                                </div>

                                                <div class="billtime">
                                                    <h:outputLabel value="#{billSearch.bill.cancelledBill.billTime}"  
                                                                   rendered="#{billSearch.bill.cancelledBill.insId ne null}">
                                                        <f:convertDateTime pattern="hh mm ss a"/>
                                                    </h:outputLabel>
                                                    <h:outputLabel value="#{billSearch.bill.refundedBill.billTime}"  
                                                                   rendered="#{billSearch.bill.refundedBill.insId ne null}">
                                                        <f:convertDateTime pattern="hh mm ss a"/>
                                                    </h:outputLabel>
                                                    <h:outputLabel value="#{billSearch.bill.billTime}" 
                                                                   rendered="#{billSearch.bill.refundedBill.insId eq null and 
                                                                               billSearch.bill.cancelledBill.insId eq null }">
                                                        <f:convertDateTime pattern="hh mm ss a"/>
                                                    </h:outputLabel>
                                                </div>

                                                <h:outputLabel value="#{billSearch.bill.patient.person.nameWithTitle}" styleClass="ptname" />

                                                <h:outputLabel value="#{billSearch.bill.patient.person.phone}" styleClass="phone" />



                                                <h:dataTable value="#{billSearch.billItems}" var="bip" styleClass="items"   >
                                                    <h:column >
                                                        <h:outputLabel value="#{bip.item.printName}" style="margin: 4px;" />
                                                    </h:column>
                                                </h:dataTable>

                                                <div class="rates" >
                                                    <h:dataTable value="#{billSearch.billItems}" var="bip1"  >
                                                        <h:column>
                                                            <h:outputLabel value="#{bip1.netValue}"  style="margin: 4px;" >
                                                                <f:convertNumber pattern="#,##0.00" />
                                                            </h:outputLabel>
                                                        </h:column>
                                                    </h:dataTable>
                                                </div>

                                                <div class="totals">
                                                    <table>
                                                        <tr>
                                                            <td>
                                                                <br/>
                                                                <br/>
                                                            </td>
                                                            <td>
                                                                <br/>
                                                                <br/>
                                                            </td>
                                                        </tr>
                                                        <tr>
                                                            <td style="text-align: left; min-width: 3cm;">
                                                                <h:outputLabel value="Total" style="  text-align: right!important;  font-size: 15px!important;   "/>
                                                            </td>
                                                            <td style="text-align: right!important; ">
                                                                <h:outputLabel value="#{billSearch.bill.total}"  style=" font-weight: bold ; text-align: right!important; font-size: 15px!important;    ">
                                                                    <f:convertNumber pattern="#,##0.00" />
                                                                </h:outputLabel>
                                                            </td>
                                                        </tr>
                                                        <tr>
                                                            <td style="text-align: left;">
                                                                <h:outputLabel  rendered="#{billSearch.bill.discount ne 0.0}" style=" text-align: right!important;  font-size: 15px!important;   "  value="Discount"/>
                                                            </td>
                                                            <td style="text-align: right!important; ">
                                                                <h:outputLabel rendered="#{billSearch.bill.discount ne 0.0}"   value="#{billSearch.bill.discount}"  style=" text-align: right!important;  font-size: 15px!important;   ">
                                                                    <f:convertNumber pattern="#,##0.00" />
                                                                </h:outputLabel>
                                                            </td>
                                                        </tr>
                                                        <tr>
                                                            <td style="text-align: left;">
                                                                <h:outputLabel  rendered="#{billSearch.bill.discount ne 0.0}"    value="Net Total" style=" text-align: right!important;  font-size: 15px!important;   "/>
                                                            </td>
                                                            <td style="text-align: right!important; ">
                                                                <h:outputLabel  rendered="#{billSearch.bill.discount ne 0.0}"    value="#{billSearch.bill.netTotal}"  style="font-weight: bold ; text-align: right!important; font-size: 15px!important;    ">
                                                                    <f:convertNumber pattern="#,##0.00" />
                                                                </h:outputLabel>
                                                            </td>
                                                        </tr>


                                                    </table>
                                                </div>

                                                <div class="cashier" >
                                                    <h:outputLabel value="Cashier : #{billSearch.bill.cancelledBill.creater.code}"  
                                                                   rendered="#{billSearch.bill.cancelledBill.insId ne null}" />
                                                    <h:outputLabel value="Cashier : #{billSearch.bill.refundedBill.creater.code}"
                                                                   rendered="#{billSearch.bill.refundedBill.insId ne null}"   />
                                                    <h:outputLabel value="Cashier : #{billSearch.bill.creater.code}" 
                                                                   rendered="#{billSearch.bill.refundedBill.insId eq null and
                                                                               billSearch.bill.cancelledBill.insId eq null }"/>


                                                </div>

                                                <div class="consult">
                                                    <h:outputLabel value="#{billSearch.bill.collectingCentre.name} #{billSearch.bill.collectingCentre.name}" />
                                                </div>

                                            </div>



                                        </h:panelGroup>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </h:panelGroup>


                </h:form>
            </ui:define>



        </ui:composition>

    </h:body>
</html>
